type TupleToObject<T extends readonly (string | number | symbol)[]> = {
  [P in T[number]]: P;
};

// 1. 语法 [P in T[number]] 遍历数组类型

// const tuple = ["tesla", "model 3", "model X", "model Y"] as const;
// type td = TupleToObject<typeof tuple>;
// const k: td = ["0", "1", "2", "3"];

const tuple = ["tesla", "model 3", "model X", "model Y"] as const;

// keyof array -> 索引
type r = TupleToObject<typeof tuple>;

// js
function tupleToObject(array: any[]) {
  const obj: any = {};

  array.forEach((val) => {
    obj[val] = val;
  });

  return obj;
}

// 1. 返回一个对象
// 2. 遍历 array  T[number]
